package com.jsh.ex.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Created by wukai on 2017/9/13.
 * 可以用initParams={@WebInitParam(name ="EXCLUDED_PAGES" , value = "login.jsp;loginAction")} 排除例外
 */
@Component
@WebFilter(urlPatterns = {"/*"},filterName = "myFilter")
public class MyFilter implements Filter {
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        String p = filterConfig.getInitParameter("EXCLUDED_PAGES");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
//        if(req.getServletPath().contains("/druid")){
//            logger.info("/druid not filter");
//        }else{
//            logger.info("myFilter is ok !");
//        }
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
